import java.util.Arrays;

/**
 * @Author ZhangCuirong
 * @Date 2025/9/8 11:11
 * @description:
 */
public class Solution91 {
    public int numDecodings(String s) {
        if (s.isEmpty()) {
            return 0;
        }
        int[] dp = new int[s.length() + 1];
        dp[0] = 1;
        dp[1] = s.charAt(0) == '0' ? 0 : 1;
        for (int i = 2; i <= s.length(); i++) {
            char c = s.charAt(i - 1);
            char d = s.charAt(i - 2);
            if (c >= '1' && c <= '9') {
                dp[i] += dp[i - 1];
            }
            if (d == '1' || d == '2' && c <= '6') {
                dp[i] += dp[i - 2];
            }

        }
        return dp[s.length()];
    }

    public static void main(String[] args) {
        Solution91 solution = new Solution91();
        System.out.println(solution.numDecodings("12"));
        System.out.println(solution.numDecodings("226"));
        System.out.println(solution.numDecodings("101"));
    }
}
